function UgovorCopyTok(btn){
	var holder = btn.parentNode;
	var tmp;
	
	//var clone = holder.cloneNode(true);
	var clone = document.createElement("div");
	clone.innerHTML = holder.innerHTML;
	
	var copyindex = UgovorCopyPasteTokGetIndex(holder.id);
	
	
	
	var elements = Array("label","input","textarea","select");
	for(var i=0; i<elements.length; i++){
		var els = clone.getElementsByTagName(elements[i]);
		for(var j=0; j<els.length; j++){
			// LABELS
			if(elements[i]=="label" && els[j].hasAttribute("for")){
				tmp = els[j].getAttribute("for").split(/_(\d+)/g);
				tmp = removeEmptyItems(tmp);
				for(var k=0; k<tmp.length; k++){
					if(tmp[k].match(/^\d+$/)){
						tmp[k] = "[COPYINDEX]";
						break;
					}
				}
				els[j].setAttribute("for",implode("_",tmp));
			// ELEMENTS
			}else if(els[j].hasAttribute("name")){
				tmp = els[j].name.split(/_(\d+)/g);
				tmp = removeEmptyItems(tmp);
				for(var k=0; k<tmp.length; k++){
					if(tmp[k].match(/^\d+$/)){
						tmp[k] = "[COPYINDEX]";
						break;
					}
				}
				els[j].name = implode("_",tmp);
				els[j].id = els[j].name;
				
				var srcelem = document.getElementById(els[j].name.replace("[COPYINDEX]",copyindex));
				switch(elements[i]){
					case "input":
						switch(els[j].type){
							case "text":
								els[j].value = srcelem.value;
								break;
							case "checkbox":
								els[j].checked = srcelem.checked?true:false;
								break;
						}
						break;
					case "textarea":
						els[j].value = srcelem.value;
						//alert(els[j].name+":"+els[j].value+"\n"+srcelem.name+": "+srcelem.value);
						break;
					case "select":
						els[j].selectedIndex = srcelem.selectedIndex;
						alert(els[j].name+":"+els[j].selectedIndex);
						break;
				}
			}
		}
	}
	document.body.YPClipBoard = clone;
	alert("Podaci su iskopirani.");
}

function UgovorPasteTok(btn){
	var holder = btn.parentNode;
	var index;
	var cb = document.body.YPClipBoard;
	if(cb){
		
		var h3 = holder.getElementsByTagName("h3")[0];
		var h31 = cb.getElementsByTagName("h3")[0];
		cb.insertBefore(h3,h31);
		cb.removeChild(h31);
		
		var index = UgovorCopyPasteTokGetIndex(holder.id);
		cb.innerHTML = cb.innerHTML.replace(/\[COPYINDEX\]/g,index);
	
		while(holder.hasChildNodes() == true){
                holder.removeChild(holder.childNodes[0]);
        }
		
		holder.appendChild(cb);
		document.body.YPClipBoard = null;
		alert("Podaci su ubačeni.");
	}
}

function UgovorCopyPasteTokGetIndex(id){
	var tmp = id.split(/_(\d+)/g);
	tmp = removeEmptyItems(tmp);
	for(var k=0; k<tmp.length; k++){
		if(tmp[k].match(/^\d+$/)){
			index = tmp[k];
			break;
		}
	}
	return index;
}